/********************************************************
 *  ██████╗  ██████╗████████╗██╗
 * ██╔════╝ ██╔════╝╚══██╔══╝██║
 * ██║  ███╗██║        ██║   ██║
 * ██║   ██║██║        ██║   ██║
 * ╚██████╔╝╚██████╗   ██║   ███████╗
 *  ╚═════╝  ╚═════╝   ╚═╝   ╚══════╝
 * Geophysical Computational Tools & Library (GCTL)
 *
 * Copyright (c) 2023  Yi Zhang (yizhang-geo@zju.edu.cn)
 *
 * GCTL is distributed under a dual licensing scheme. You can redistribute 
 * it and/or modify it under the terms of the GNU Lesser General Public 
 * License as published by the Free Software Foundation, either version 2 
 * of the License, or (at your option) any later version. You should have 
 * received a copy of the GNU Lesser General Public License along with this 
 * program. If not, see <http://www.gnu.org/licenses/>.
 * 
 * If the terms and conditions of the LGPL v.2. would prevent you from using 
 * the GCTL, please consider the option to obtain a commercial license for a 
 * fee. These licenses are offered by the GCTL's original author. As a rule, 
 * licenses are provided "as-is", unlimited in time for a one time fee. Please 
 * send corresponding requests to: yizhang-geo@zju.edu.cn. Please do not forget 
 * to include some description of your company and the realm of its activities. 
 * Also add information on how to contact you by electronic and paper mail.
 ******************************************************/

#ifndef _FFT_FILTER_H
#define _FFT_FILTER_H

#include "../core.h"
#include "fft.h"
#include "math.h"

namespace gctl
{
    class fft_filter
    {
    public:
        /**
         * @brief Construct a new fft filter object
         * 
         * @param fi_type Filting type
         * @param fr_type Filter type
         * @param order Filter order
         * @param fs Sampling frequency
         * @param f1 First filtering frequency. This is needed for low/high pass filters
         * @param f2 Second filtering frequency. This is needed for band pass or band stop filters
         */
        fft_filter(filting_type_e fi_type, filter_type_e fr_type, int order, double fs, double f1, double f2 = 0);

        /**
         * @brief Default constructor
         * 
         */
        fft_filter();

        /**
         * @brief Default de-constructor
         * 
         */
        virtual ~fft_filter();

        /**
         * @brief Initiate a fft filter object
         * 
         * @param fi_type Filting type
         * @param fr_type Filter type
         * @param order Filter order
         * @param fs Sampling frequency
         * @param f1 First filtering frequency. This is needed for low/high pass filters
         * @param f2 Second filtering frequency. This is needed for band pass or band stop filters
         */
        void init(filting_type_e fi_type, filter_type_e fr_type, int order, double fs, double f1, double f2 = 0);

        /**
         * @brief Filt the input data using the initiated filter. Phase shift is corrected automatically
         * 
         * @param in Input data
         * @param out OUtput data
         */
        void filter(const array<double> &in, array<double> &out);

    private:
        int odr_;
        double fs_, fl_, fh_;
        filting_type_e fi_type_;
        filter_type_e fr_type_;
        array<double> din_;
        array<double> dout_;
        array<double> fid_;
        array<std::complex<double> > freqs_;
    };
}

#endif // _FFT_FILTER_H